# 准备工作
import ALG as alg
import tkinter as tk

# 弹窗可重复使用
# 弹窗1
window = tk.Tk()
window.title('面积计算器')
window.geometry('230x120')
var = tk.StringVar()
label = tk.Label(window, text='选择图形类型', bg='green',
                 width=15, height=2)
label.pack()


# 按按钮后的响应函数
def hit_a():
    # 弹窗2
    window2 = tk.Toplevel(window)
    window2.geometry('300x120')
    window2.title('选择长度单位')
    # 弹窗2-按钮
    a1 = tk.Radiobutton(window2, text='A.厘米',
                        variable=var, value='A',
                        command=hit_aa)
    a1.pack()
    a2 = tk.Radiobutton(window2, text='B.英寸',
                        variable=var, value='B',
                        command=hit_ab)
    a2.pack()


def hit_b():
    window2 = tk.Toplevel(window)
    window2.geometry('300x120')
    window2.title('选择长度单位')

    b1 = tk.Radiobutton(window2, text='A.厘米',
                        variable=var, value='A',
                        command=hit_ba)
    b1.pack()

    b2 = tk.Radiobutton(window2, text='B.英寸',
                        variable=var, value='B',
                        command=hit_bb)
    b2.pack()


def hit_c():
    window2 = tk.Toplevel(window)
    window2.geometry('300x120')
    window2.title('选择长度单位')

    c1 = tk.Radiobutton(window2, text='A.厘米',
                        variable=var, value='A',
                        command=hit_ca)
    c1.pack()

    c2 = tk.Radiobutton(window2, text='B.英寸',
                        variable=var, value='B',
                        command=hit_cb)
    c2.pack()


def hit_aa():
    # 弹窗3
    window3 = tk.Tk()
    window3.title('请分别输入长,宽')
    window3.geometry('300x120')

    def rec():
        len1 = my_entry1.get()
        len2 = my_entry2.get()
        d1 = float(len1)
        d2 = float(len2)
        alg.rectangle(d1, d2, '1')

    my_label1 = tk.Label(window3, text="矩形的长是")
    my_label1.grid(row=0, column=0)
    my_entry1 = tk.Entry(window3)
    my_entry1.grid(row=0, column=1)

    my_label2 = tk.Label(window3, text="矩形的宽是")
    my_label2.grid(row=1, column=0)
    my_entry2 = tk.Entry(window3)
    my_entry2.grid(row=1, column=1)

    my_button = tk.Button(window3, text="Submit", command=rec)
    my_button.grid(row=2, column=1)


def hit_ab():
    window3 = tk.Tk()
    window3.title('请分别输入长,宽')
    window3.geometry('300x120')

    def rec():
        len1 = my_entry1.get()
        len2 = my_entry2.get()
        d1 = float(len1)
        d2 = float(len2)
        alg.rectangle(d1, d2, '2')

    my_label1 = tk.Label(window3, text="矩形的长是")
    my_label1.grid(row=0, column=0)
    my_entry1 = tk.Entry(window3)
    my_entry1.grid(row=0, column=1)

    my_label2 = tk.Label(window3, text="矩形的宽是")
    my_label2.grid(row=1, column=0)
    my_entry2 = tk.Entry(window3)
    my_entry2.grid(row=1, column=1)

    my_button = tk.Button(window3, text="Submit", command=rec)
    my_button.grid(row=2, column=1)


def hit_ba():
    window3 = tk.Tk()
    window3.title('请分别输入底,高')
    window3.geometry('300x120')

    def tri():
        len1 = my_entry1.get()
        len2 = my_entry2.get()
        d1 = float(len1)
        d2 = float(len2)
        alg.triangle(d1, d2, '1')

    my_label1 = tk.Label(window3, text="三角形的底是")
    my_label1.grid(row=0, column=0)
    my_entry1 = tk.Entry(window3)
    my_entry1.grid(row=0, column=1)

    my_label2 = tk.Label(window3, text="三角形的高是")
    my_label2.grid(row=1, column=0)
    my_entry2 = tk.Entry(window3)
    my_entry2.grid(row=1, column=1)

    my_button = tk.Button(window3, text="Submit", command=tri)
    my_button.grid(row=2, column=1)


def hit_bb():
    window3 = tk.Tk()
    window3.title('请分别输入底,高')
    window3.geometry('300x120')

    def tri():
        len1 = my_entry1.get()
        len2 = my_entry2.get()
        d1 = float(len1)
        d2 = float(len2)
        alg.triangle(d1, d2, '2')

    my_label1 = tk.Label(window3, text="三角形的底是")
    my_label1.grid(row=0, column=0)
    my_entry1 = tk.Entry(window3)
    my_entry1.grid(row=0, column=1)

    my_label2 = tk.Label(window3, text="三角形的高是")
    my_label2.grid(row=1, column=0)
    my_entry2 = tk.Entry(window3)
    my_entry2.grid(row=1, column=1)

    my_button = tk.Button(window3, text="Submit", command=tri)
    my_button.grid(row=2, column=1)


def hit_ca():
    window3 = tk.Tk()
    window3.title('请输入直径')
    window3.geometry('300x120')

    def cir():
        len1 = my_entry1.get()
        d1 = float(len1)
        alg.circle(d1, '1')
        # do stuff with url_member

    my_label1 = tk.Label(window3, text="圆的直径是")
    my_label1.grid(row=0, column=0)
    my_entry1 = tk.Entry(window3)
    my_entry1.grid(row=0, column=1)

    my_button = tk.Button(window3, text="Submit", command=cir)
    my_button.grid(row=1, column=1)


def hit_cb():
    window3 = tk.Tk()
    window3.title('请输入直径')
    window3.geometry('300x120')

    def cir():
        len1 = my_entry1.get()
        d1 = float(len1)
        alg.circle(d1, '2')

    my_label1 = tk.Label(window3, text="圆的直径是")
    my_label1.grid(row=0, column=0)
    my_entry1 = tk.Entry(window3, text = var)
    my_entry1.grid(row=0, column=1)

    my_button = tk.Button(window3, text="Submit", command=cir)
    my_button.grid(row=1, column=1)


# 弹窗1-按钮
r1 = tk.Radiobutton(window, text='A.矩形',
                    variable=var, value='A',
                    command=hit_a)
r1.pack()

r2 = tk.Radiobutton(window, text='B.三角形',
                    variable=var, value='B',
                    command=hit_b)
r2.pack()

r3 = tk.Radiobutton(window, text='C.圆形',
                    variable=var, value='C',
                    command=hit_c)
r3.pack()

window.mainloop()
